package repo

import (
	"mlss-cc-a/datasource"
	"mlss-cc-a/logger"
	"strconv"
)

const TableNamePerson = "person"

var PersonRepo PersonRepoIF

type PersonRepoIF interface {
	GetPersonList(id int64) ([]Person, error)
}
type PersonRepoImpl struct {
	BaseRepoImpl
}

func init() {
	PersonRepo = &PersonRepoImpl{
		BaseRepoImpl{
			TableName: TableNamePerson,
		},
	}
}

type Person struct {
	// 时间
	Birth string `json:"birth"`

	// 编码
	Code string `json:"code"`

	// 邮箱
	Email string `json:"email"`

	// Id
	ID int64 `json:"id"`

	// 姓名
	Name string `json:"name"`

	// 手机号码
	Phone string `json:"phone"`
}

func (u *PersonRepoImpl) GetPersonList(id int64) ([]Person, error) {
	var person []Person

	datasource.DB.Debug().Table(u.TableName).Where("id < ?", id).Order("id desc").
		Find(&person)

	log := logger.Logger()

	for _, u := range person {
		log.Infof("user is : " + strconv.FormatInt(u.ID, 10) + u.Name)
	}

	return person, nil
}
